<?php
App::uses('AppController', 'Controller');
/**
 * Teachers Controller
 *
 * @property Teacher $Teacher
 * @property PaginatorComponent $Paginator
 */
class TeachersController extends AppController {

/**
 * Components
 *
 * @var array
 */
	public $components = array('Paginator');
	
	public $SideBarItems = array();
	public $SideBarMessage = '';
	public $HMenu = '';
	public $VMenu = '';
	
	public $SessionUserData = '';
	
	public function beforeFilter() {
		AppController::beforeFilter();
	
	
		$this->set('SideBarMessage', $this->SideBarMessage);
		$this->set('HMenu', $this->HMenu);
		
		$this->SessionUserData = $this->Session->read('SessionUserData');
	
	}

/**
 * index method
 *
 * @return void
 */
	public function index() {
		// читаем id  
		$id = $this->SessionUserData;
		
		$this->set('HMenu', 'Teacher');
		
		$options = array('conditions' => array('Teacher.' . $this->Teacher->primaryKey => $id));
		$this->set('teacher', $this->Teacher->find('first', $options));
		
	}

/**
 * view method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
	public function view($id = null) {
		// читаем id
		$id = $this->SessionUserData;
		
		if (!$this->Teacher->exists($id)) {
			throw new NotFoundException(__('Invalid teacher'));
		}
		$options = array('conditions' => array('Teacher.' . $this->Teacher->primaryKey => $id));
		$this->set('teacher', $this->Teacher->find('first', $options));
	}

/**
 * add method
 *
 * @return void
 */
	public function add() {
		if ($this->request->is('post')) {
			$this->Teacher->create();
			if ($this->Teacher->save($this->request->data)) {
				$this->Session->setFlash(__('The teacher has been saved.'));
				return $this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The teacher could not be saved. Please, try again.'));
			}
		}
		$departments = $this->Teacher->Department->find('list');
		$pozitions = $this->Teacher->Pozition->find('list');
		$this->set(compact('departments', 'pozitions'));
	}

/**
 * edit method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
	public function edit($id = null) {
		// читаем id
		$id = $this->SessionUserData;
		$this->set('HMenu', 'Teacher');
		
		//debug($this->request->data);
		//die();
		
		if (!$this->Teacher->exists($id)) {
			throw new NotFoundException(__('Invalid teacher'));
		}
		if ($this->request->is(array('post', 'put')) && !isset($this->data['Teacher']['doedit'])) {
			if ($this->Teacher->save($this->request->data)) {
				$this->Session->setFlash(__('The teacher has been saved.'));
				return $this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The teacher could not be saved. Please, try again.'));
			}
		} else {
			$options = array('conditions' => array('Teacher.' . $this->Teacher->primaryKey => $id));
			$this->request->data = $this->Teacher->find('first', $options);
		}
		$departments = $this->Teacher->Department->find('list');
		$pozitions = $this->Teacher->Pozition->find('list');
		$this->set(compact('departments', 'pozitions'));
	}

/**
 * delete method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
/* 	public function delete($id = null) {
		$this->Teacher->id = $id;
		if (!$this->Teacher->exists()) {
			throw new NotFoundException(__('Invalid teacher'));
		}
		$this->request->onlyAllow('post', 'delete');
		if ($this->Teacher->delete()) {
			$this->Session->setFlash(__('The teacher has been deleted.'));
		} else {
			$this->Session->setFlash(__('The teacher could not be deleted. Please, try again.'));
		}
		return $this->redirect(array('action' => 'index'));
	} */
}
